# Pygame 使用数字键盘键移动
# 如果我们想在游戏窗口中实现一个物体的对角线移动，我们需要使用数字键盘键。4、6、8和2键对应于左、右、上、下箭头，而数字键7、9、3和1可以用来将物体进行左上、右上、右下和左下的斜向移动。这些键被Pygame识别为以下数值 –
#
# K_KP1       keypad 1
# K_KP2       keypad 2
# K_KP3       keypad 3
# K_KP4       keypad 4
# K_KP5       keypad 5
# K_KP6       keypad 6
# K_KP7       keypad 7
# K_KP8       keypad 8
# K_KP9       keypad 9
image_filename = '../../pygame.png'
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen = pygame.display.set_mode((400,300))
pygame.display.set_caption("Moving with arrows")
img = pygame.image.load(image_filename)
x = 0
y= 150
while True:
   screen.fill((255,255,255))
   screen.blit(img, (x, y))
   for event in pygame.event.get():
      if event.type == QUIT:
         exit()
      if event.type == KEYDOWN:
         if event.key == K_KP6:
            x= x+5
         if event.key == K_KP4:
            x=x-5
         if event.key == K_KP8:
            y=y-5
         if event.key == K_KP2:
            y=y+5
         if event.key == K_KP7:
            x=x-5
            y=y-5
         if event.key == K_KP9:
            x=x+5
            y=y-5
         if event.key == K_KP3:
            x=x+5
            y=y+5
         if event.key == K_KP1:
            x=x-5
            y=y+5
   pygame.display.update()